import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

/* Router Modules */
import componentsRouter from './modules/components'
import chartsRouter from './modules/charts'
import tableRouter from './modules/table'
import nestedRouter from './modules/nested'

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
 roles: ['admin','editor']    control the page roles (you can set multiple roles)
 title: 'title'               the name show in sidebar and breadcrumb (recommend set)
 icon: 'svg-name'/'el-icon-x' the icon show in the sidebar
 noCache: true                if set true, the page will no be cached(default is false)
 affix: true                  if set true, the tag will affix in the tags-view
 breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
 activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
 }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [
    {
        path: '/redirect',
        component: Layout,
        hidden: true,
        children: [
            {
                path: '/redirect/:path(.*)',
                component: () => import('@/views/redirect/index')
            }
        ]
    },
    {
        path: '/share',
        component: () => import('@/views/bs/share'),
        hidden: true,
        meta: {
            title: '文件分享',
            requiresAuth: false
        }
    },
  {
    path: '/scan',
    component: () => import('@/views/bs/scan'),
    hidden: true,
    meta: {
      title: '扫描二维码',
      requiresAuth: false
    }
  },
  {
    path: '/station',
    component: () => import('@/views/bs/station'),
    hidden: true,
    meta: {
      title: '工位详情',
      requiresAuth: false
    }
  },
  {
    path: '/stationFileDetail',
    component: () => import('@/views/bs/stationFileDetail.vue'),
    hidden: true,
    meta: {
      title: '工位文件详情',
      requiresAuth: false
    }
  },
  {
    path: '/oidc',
    component: () => import('@/views/bs/oidc'),
    hidden: true,
    meta: {
      title: '用户登陆',
      requiresAuth: false
    }
  },
    {
        path: '/login',
        component: () => import('@/views/login/index'),
        hidden: true
    },
    {
        path: '/auth-redirect',
        component: () => import('@/views/login/auth-redirect'),
        hidden: true
    },
    // {
    //   path: '/bs/search',
    //   component: () => import('@/views/bs/share'),
    //   hidden: true,
    //     meta: {
    //   title: '搜索',
    //   icon: 'lock',
    //   roles: ['*'] // you can set roles in root nav
    // },
    // },

    {
        path: '/404',
        component: () => import('@/views/error-page/404'),
        hidden: true
    },
    {
        path: '/401',
        component: () => import('@/views/error-page/401'),
        hidden: true
    },
    // {
    //   path: '/',
    //   component: Layout,
    //   redirect: '/dashboard',
    //   children: [
    //     {
    //       path: 'dashboard',
    //       component: () => import('@/views/dashboard/index'),
    //       name: 'Dashboard',
    //       meta: { title: 'dashboard', icon: 'dashboard', affix: true }
    //     }
    //   ]
    // },
    {
        path: '/',
        component: Layout,

        redirect: '/bs/search'
    },
    {
        path: '/dashboard',
        component: Layout,

        redirect: '/bs/search'
    },
    // {
    //   path: '/manger',
    //   component: Layout,
    //   redirect: '/example/list',
    //   name: 'System',
    //   meta: {
    //     title: "系统设置",
    //     icon: 'el-icon-s-help'
    //   },
    //   children: [
    //     {
    //       path: '/manger/login',
    //       component: () => import('@/views/table/sl_login'),
    //       name: 'manger_login',
    //       meta: { title: '后台管理员设置', icon: 'el-icon-receiving' }
    //     },
    //     {
    //       path: '/manger/role',
    //       component: () => import('@/views/table/sl_role'),
    //       name: 'qxz',
    //       meta: { title: '权限组管理', icon: 'el-icon-collection' }
    //     },
    //     {
    //       path: '/manger/valdict',
    //       component: () => import('@/views/table/sl_valdict'),
    //       name: 'valdict',
    //       meta: { title: '数据字典', icon: 'el-icon-files' }
    //     },
    //     {
    //       path: '/manger/nav',
    //       component: () => import('@/views/table/sl_nav'),
    //       name: 'nav',
    //       meta: { title: '菜单管理', icon: 'el-icon-notebook-1' }
    //     },
    //     {
    //       path: '/manger/routemap',
    //       component: () => import('@/views/table/bsrouter'),
    //       name: 'routemap',
    //       meta: { title: '路由设置', icon: 'el-icon-toilet-paper' }
    //     },
    //     {
    //       path: '/manger/routerole',
    //       component: () => import('@/views/manger/routerole'),
    //       name: 'routerole',
    //       meta: { title: '路由权限', icon: 'el-icon-office-building' }
    //     },
    //     {
    //       path: '/manger/templaterole',
    //       component: () => import('@/views/manger/templaterole'),
    //       name: 'routerole',
    //       meta: { title: '模板权限', icon: 'el-icon-office-building' }
    //     },
    //     {
    //       path: '/manger/clear_cache',
    //       redirect: '/error/404',
    //       component: () => import('@/views/table/bsrouter'),
    //       name: 'cache',
    //       meta: { title: '清除缓存', icon: 'el-icon-table-lamp' }
    //     },
    //     {
    //       path: 'edit/:id(\\d+)',
    //       component: () => import('@/views/example/edit'),
    //       name: 'EditArticle',
    //       meta: { title: 'editArticle', noCache: true, activeMenu: '/example/list' },
    //       hidden: true
    //     },
    //     {
    //       path: '/bs/sl_department',
    //       component: () => import('@/views/table/sl_department'),
    //       name: 'ComplexTable',
    //       meta: { title: "产线管理", icon: 'el-icon-suitcase', affix: true }
    //     },
    //     {
    //       path: '/bs/sl_station',
    //       component: () => import('@/views/table/sl_station'),
    //       name: 'ComplexTable',
    //       meta: { title: "工站管理", icon: 'component', affix: true }
    //     },
    //
    //     {
    //       path: '/bs/technology',
    //       component: () => import('@/views/table/technology'),
    //       name: 'Technology',
    //       meta: { title: "工艺管理", icon: 'table', affix: true }
    //     },
    //     {
    //       path: '/bs/template',
    //       component: () => import('@/views/dashboard/index'),
    //       name: 'Template',
    //       meta: { title: '模板编辑', icon: 'dashboard', affix: true }
    //     },
    //     {
    //       path: '/Report',
    //       // component: Layout,
    //       redirect: '/example/list',
    //       name: 'Report',
    //       meta: {
    //         title: "Report报表",
    //         icon: 'el-icon-watch-1'
    //       },
    //       children: [
    //         {
    //           path: '/Report/dataview',
    //           redirect: '/error/404',
    //           component: () => import('@/views/table/bsrouter'),
    //           name: 'dataview',
    //           meta: { title: '数据看板', icon: 'el-icon-film' }
    //         },
    //         {
    //           path: '/Report/dataview1',
    //           redirect: '/error/404',
    //           component: () => import('@/views/table/bsrouter'),
    //           name: 'dataview1',
    //           meta: { title: '数据报表', icon: 'el-icon-s-operation' }
    //         },
    //       ]
    //     },
    //   ]
    // },
    // {
    //   path: '/Knowledge',
    //   component: Layout,
    //   redirect: '/example/list',
    //   name: 'Knowledge',
    //   meta: {
    //     title: "Knowledge 知识",
    //     icon: 'el-icon-postcard'
    //   },
    //   children: [
    //     {
    //       path: '/Knowledge/mea',
    //       component: () => import('@/views/documentation/index'),
    //       name: 'mea',
    //       meta: { title: 'MEA项目', icon: 'el-icon-wallet' }
    //     },
    //     {
    //       path: '/Knowledge/Process',
    //       component: () => import('@/views/documentation/index'),
    //       name: 'Process',
    //       meta: { title: 'Process工艺', icon: 'el-icon-discount' }
    //     },
    //     {
    //       path: '/Knowledge/Maintenance',
    //       component: () => import('@/views/documentation/index'),
    //       name: 'Maintenance',
    //       meta: { title: 'Maintenance维护', icon: 'el-icon-price-tag' }
    //     },
    //     {
    //       path: '/Knowledge/Spareparts',
    //       component: () => import('@/views/documentation/index'),
    //       name: 'Spareparts',
    //       meta: { title: 'Spareparts备件', icon: 'el-icon-news' }
    //     },
    //   ]
    // },
    // {
    //   path: '/Application',
    //   component: Layout,
    //   redirect: '/example/list',
    //   name: 'Application',
    //   meta: {
    //     title: "Application智能应用",
    //     icon: 'el-icon-medal'
    //   },
    //   children: [
    //     {
    //       path: '/Application/Study',
    //       redirect: '/error/404',
    //       component: () => import('@/views/table/bsrouter'),
    //       name: 'Study',
    //       meta: { title: 'Study学习', icon: 'el-icon-news' }
    //     },
    //     {
    //       path: '/Application/gzfx',
    //       redirect: '/error/404',
    //       component: () => import('@/views/table/bsrouter'),
    //       name: 'gzfx',
    //       meta: { title: '故障资料分析', icon: 'el-icon-guide' }
    //     },
    //     {
    //       path: '/Application/bjfx',
    //       redirect: '/error/404',
    //       component: () => import('@/views/table/bsrouter'),
    //       name: 'bjfx',
    //       meta: { title: '备件分析', icon: 'el-icon-guide' }
    //     },
    //     {
    //       path: '/Application/workplace',
    //       redirect: '/error/404',
    //       component: () => import('@/views/table/bsrouter'),
    //       name: 'workplace',
    //       meta: { title: 'My workplace', icon: 'el-icon-cpu' }
    //     },
    //   ]
    // },
    // {
    //   path: '/Report',
    //   component: Layout,
    //   redirect: '/example/list',
    //   name: 'Report',
    //   meta: {
    //     title: "Report报表",
    //     icon: 'el-icon-watch-1'
    //   },
    //   children: [
    //     {
    //       path: '/Report/dataview',
    //       redirect: '/error/404',
    //       component: () => import('@/views/table/bsrouter'),
    //       name: 'dataview',
    //       meta: { title: '数据看板', icon: 'el-icon-film' }
    //     },
    //     {
    //       path: '/Report/dataview1',
    //       redirect: '/error/404',
    //       component: () => import('@/views/table/bsrouter'),
    //       name: 'dataview1',
    //       meta: { title: '数据报表', icon: 'el-icon-s-operation' }
    //     },
    //   ]
    // },
    // {
    //   path: '/documentation',
    //   component: Layout,
    //   children: [
    //     {
    //       path: 'index',
    //       component: () => import('@/views/documentation/index'),
    //       name: 'Documentation',
    //       meta: { title: '文件管理', icon: 'documentation', affix: true }
    //     }
    //   ]
    // },

    // {
    //   path: '/bsrouter',
    //   component: Layout,
    //   children: [
    //     {
    //       path: 'bsrouter',
    //       component: () => import('@/views/table/bsrouter'),
    //       name: 'ComplexTable',
    //       meta: { title: "路由设置", icon: 'el-icon-connection', affix: true }
    //     }
    //   ]
    // },
    {
        path: '/profile',
        component: Layout,
        redirect: '/profile/index',
        hidden: true,
        children: [
            {
                path: 'index',
                component: () => import('@/views/profile/index'),
                name: 'Profile',
                meta: {title: 'profile', icon: 'user', noCache: true}
            }
        ]
    }
]

/**
 * asyncRoutes
 * the routes that need to be dynamically loaded based on user roles
 */
export const asyncRoutes = [
//   {
//   path: '/permission',
//   component: Layout,
//   redirect: '/permission/page',
//   alwaysShow: true, // will always show the root menu
//   name: 'Permission',
//   meta: {
//     title: 'permission',
//     icon: 'lock',
//     roles: ['admin', 'editor'] // you can set roles in root nav
//   },
//   children: [
//     {
//       path: 'page',
//       component: () => import('@/views/permission/page'),
//       name: 'PagePermission',
//       meta: {
//         title: 'pagePermission',
//         roles: ['admin'] // or you can only set roles in sub nav
//       }
//     },
//     {
//       path: 'directive',
//       component: () => import('@/views/permission/directive'),
//       name: 'DirectivePermission',
//       meta: {
//         title: 'directivePermission'
//         // if do not set roles, means: this page does not require permission
//       }
//     },
//     {
//       path: 'role',
//       component: () => import('@/views/permission/role'),
//       name: 'RolePermission',
//       meta: {
//         title: 'rolePermission',
//         roles: ['admin']
//       }
//     }
//   ]
// },

    //
    // {
    //   path: '/icon',
    //   component: Layout,
    //   children: [
    //     {
    //       path: 'index',
    //       component: () => import('@/views/icons/index'),
    //       name: 'Icons',
    //       meta: { title: 'icons', icon: 'icon', noCache: true }
    //     }
    //   ]
    // },
    //
    // /** when your routing map is too long, you can split it into small modules **/
    // componentsRouter,
    // chartsRouter,
    // nestedRouter,
    // tableRouter,
    //

    //
    // {
    //   path: '/tab',
    //   component: Layout,
    //   children: [
    //     {
    //       path: 'index',
    //       component: () => import('@/views/tab/index'),
    //       name: 'Tab',
    //       meta: { title: 'tab', icon: 'tab' }
    //     }
    //   ]
    // },
    //
    {
        path: '/error',
        component: Layout,
        redirect: 'noRedirect',
        name: 'ErrorPages',
        hidden: true,
        meta: {
            title: 'errorPages',
            icon: '404'
        },
        children: [
            {
                path: '401',
                component: () => import('@/views/error-page/401'),
                name: 'Page401',
                meta: {title: 'page401', noCache: true}
            },
            {
                path: '404',
                component: () => import('@/views/error-page/404'),
                name: 'Page404',
                meta: {title: 'page404', noCache: true}
            }
        ]
    },
    {
        path: '/edit',
        component: Layout,
        redirect: 'noRedirect',
        name: 'edit',
        hidden: true,
        children: [
            {
                path: 'template/:id',
                component: () => import('@/views/bs/edit_template'),
                name: 'template_edit',
                meta: {title: '模板编辑', noCache: true}
            }
        ]
    }
    //
    // {
    //   path: '/error-log',
    //   component: Layout,
    //   children: [
    //     {
    //       path: 'log',
    //       component: () => import('@/views/error-log/index'),
    //       name: 'ErrorLog',
    //       meta: { title: 'errorLog', icon: 'bug' }
    //     }
    //   ]
    // },
    //
    // {
    //   path: '/excel',
    //   component: Layout,
    //   redirect: '/excel/export-excel',
    //   name: 'Excel',
    //   meta: {
    //     title: 'excel',
    //     icon: 'excel'
    //   },
    //   children: [
    //     {
    //       path: 'export-excel',
    //       component: () => import('@/views/excel/export-excel'),
    //       name: 'ExportExcel',
    //       meta: { title: 'exportExcel' }
    //     },
    //     {
    //       path: 'export-selected-excel',
    //       component: () => import('@/views/excel/select-excel'),
    //       name: 'SelectExcel',
    //       meta: { title: 'selectExcel' }
    //     },
    //     {
    //       path: 'export-merge-header',
    //       component: () => import('@/views/excel/merge-header'),
    //       name: 'MergeHeader',
    //       meta: { title: 'mergeHeader' }
    //     },
    //     {
    //       path: 'upload-excel',
    //       component: () => import('@/views/excel/upload-excel'),
    //       name: 'UploadExcel',
    //       meta: { title: 'uploadExcel' }
    //     }
    //   ]
    // },
    //
    // {
    //   path: '/zip',
    //   component: Layout,
    //   redirect: '/zip/download',
    //   alwaysShow: true,
    //   name: 'Zip',
    //   meta: { title: 'zip', icon: 'zip' },
    //   children: [
    //     {
    //       path: 'download',
    //       component: () => import('@/views/zip/index'),
    //       name: 'ExportZip',
    //       meta: { title: 'exportZip' }
    //     }
    //   ]
    // },
    //
    // {
    //   path: '/pdf',
    //   component: Layout,
    //   redirect: '/pdf/index',
    //   children: [
    //     {
    //       path: 'index',
    //       component: () => import('@/views/pdf/index'),
    //       name: 'PDF',
    //       meta: { title: 'pdf', icon: 'pdf' }
    //     }
    //   ]
    // },
    // {
    //   path: '/pdf/download',
    //   component: () => import('@/views/pdf/download'),
    //   hidden: true
    // },
    //
    // {
    //   path: '/theme',
    //   component: Layout,
    //   children: [
    //     {
    //       path: 'index',
    //       component: () => import('@/views/theme/index'),
    //       name: 'Theme',
    //       meta: { title: 'theme', icon: 'theme' }
    //     }
    //   ]
    // },
    //
    // {
    //   path: '/clipboard',
    //   component: Layout,
    //   children: [
    //     {
    //       path: 'index',
    //       component: () => import('@/views/clipboard/index'),
    //       name: 'ClipboardDemo',
    //       meta: { title: 'clipboardDemo', icon: 'clipboard' }
    //     }
    //   ]
    // },
    //
    // {
    //   path: '/i18n',
    //   component: Layout,
    //   children: [
    //     {
    //       path: 'index',
    //       component: () => import('@/views/i18n-demo/index'),
    //       name: 'I18n',
    //       meta: { title: 'i18n', icon: 'international' }
    //     }
    //   ]
    // },
    //
    // {
    //   path: 'external-link',
    //   component: Layout,
    //   children: [
    //     {
    //       path: 'https://github.com/PanJiaChen/vue-element-admin',
    //       meta: { title: 'externalLink', icon: 'link' }
    //     }
    //   ]
    // },
    //
    // // 404 page must be placed at the end !!!
    // { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
    mode: 'history', // require service support
    scrollBehavior: () => ({y: 0}),
    routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
    const newRouter = createRouter()
    router.matcher = newRouter.matcher // reset router
}



    export default router
